#ifndef TCP_SOCKET_H
#define TCP_SOCKET_H
#pragma execution_character_set("utf-8")
#include <QObject>
#include <QTcpSocket>
#include <QDataStream>
#include <QDebug>
#include <QJsonDocument>
#include <QJsonObject>
#include <QDateTime>
#include <QTimer>
class Common;
#include <common.h>
#include <enum_type.h>
class tcp_socket:public QTcpSocket
{
    Q_OBJECT
public:
    tcp_socket(qintptr socketDescriptor);
    bool tcpSocket_init();
    qintptr socketDescriptor;
    void send_message(QString id,QString type,QString data);
    QString      name;
    ~tcp_socket();                                              //析构
private:
    QString      type;                                          //连接类型
    QByteArray receive_data;                                    //接受的信息
    qint64     receive_datasize=0;                              //接受信息大小
    qint32 feature=19960108;                                    //tcp包标识符
    void analyse_data();                                        //拆包
    void process_data(QByteArray data);                         //处理数据
    QByteArray json_pack(QString id,QString type,QString data); //json封装
    QStringList json_analyse(QByteArray data);                  //json解析
    void send_data(QByteArray data);                            //发送数据
    QDateTime      LastConnectTime;                             //最后一次连接时间
private slots:
    void receive();                                             //接受来自外部信息
    void disconnect_Allsocket();
    void send_messagefromslot(QString id,QString type,QString data,tcp_socket *t_socket,emit_type e_type,QString sockettype);
    void IsConnect();
    void socket_delete(tcp_socket *socket);
signals:
    void send_ReplyData(QString id,QString type,QString data);  //转发信息给处理模块

};

#endif // TCP_SOCKET_H
